From 2f66faf58791df4dbbbb46cf212e5d063941a9e8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 20 Mar 2017 12:43:44 -0700 Subject: [PATCH] Detect cyclic dependencies through [replace] Previously this'd cause a stack overflow in Cargo later in the compilation graph, but this is intended to get caught during resolution. Closes #3831 --- src/cargo/core/resolver/mod.rs | 6 +++++- tests/overrides.rs | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 4943f6fe2..40bb734db 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -1023,13 +1023,17 @@ fn check_cycles(resolve: &Resolve, // dependencies. if checked.insert(id) { let summary = summaries[id]; - for dep in resolve.deps(id) { + for dep in resolve.deps_not_replaced(id) { let is_transitive = summary.dependencies().iter().any(|d| { d.matches_id(dep) && d.is_transitive() }); let mut empty = HashSet::new(); let visited = if is_transitive {&mut *visited} else {&mut empty}; visit(resolve, dep, summaries, visited, checked)?; + + if let Some(id) = resolve.replacement(dep) { + visit(resolve, id, summaries, visited, checked)?; + } } } diff --git a/tests/overrides.rs b/tests/overrides.rs index 4095cedf2..24d841905 100644 --- a/tests/overrides.rs +++ b/tests/overrides.rs @@ -1162,3 +1162,38 @@ fn override_with_default_feature() { assert_that(p.cargo_process("run"), execs().with_status(0)); } + +#[test] +fn override_plus_dep() { + Package::new("bar", "0.1.0").publish(); + + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1" + + [replace] + 'bar:0.1.0' = { path = "bar" } + "#) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + + [dependencies] + foo = { path = ".." } + "#) + .file("bar/src/lib.rs", ""); + + assert_that(p.cargo_process("build"), + execs().with_status(101).with_stderr_contains("\ +error: cyclic package dependency: [..] +")); +} -- 2.30.2